/*
 * Block comments with details of changes
 */
public without Sharing  class ReturnOrderListHandler
{
    ////删除退货申请明细的时候 取消关联对应的退货通知单明细关联退货申请
    public static void DeleteHandler(List<ReturnOrderList__c> orderList)
    {
        Set<Id> rrlIds = new Set<Id>();
        for(ReturnOrderList__c ro :orderList){
        	if(ro.ReturnRequisitionList__c != null){
            	rrlIds.add(ro.ReturnRequisitionList__c);
            }
        }
        if(rrlIds.size()>0){
        	List<ReturnRequisitionList__c> rrList = [select Id, ReturnOrder__c from ReturnRequisitionList__c where Id in:rrlIds];
            for(ReturnRequisitionList__c rr: rrList){
            	rr.ReturnOrder__c = null;
            }
            if(rrList.size()>0)update rrList;
        }
        
    }

     ////返写到退货通知单明细
    public static void rebackReturnRequisition(List<ReturnOrder__c> orderList,Map<Id,ReturnOrder__c> oldMap )
    {
        Set<Id> rrlIds = new Set<Id>();
       for(ReturnOrder__c ro :orderList){

            ReturnOrder__c old = oldMap.get(ro.Id );

            if((old.Done__c != ro.Done__c  || old.NCreturnNumber__c != ro.NCreturnNumber__c) ){
                rrlIds.add(ro.Id);
            }
            


        }
        List<ReturnRequisitionList__c> rrL = new List<ReturnRequisitionList__c>();
        for(ReturnOrderList__c ro :[select ReturnOrderList__r.Done__c ,ReturnOrderList__r.NCreturnNumber__c,ReturnRequisitionList__c  from ReturnOrderList__c where  ReturnRequisitionList__c != null and  ReturnOrderList__c in: rrlIds ]){

            rrL.add(new ReturnRequisitionList__c(Id=ro.ReturnRequisitionList__c, Done__c=ro.ReturnOrderList__r.Done__c, NCreturnNumber__c=ro.ReturnOrderList__r.NCreturnNumber__c ));
            
        
        }
        if(!rrl.isEmpty())update rrl;
        
        
    }


}